import java.util.Stack;

/**
 * @program: leetcode020
 * @author: JCM
 * @create: 2023-02-26 13:24
 * @description:
 **/
public class Main {
    public static void main(String[] args) {
        String s = "[][][[]]";
        // 创建一个栈用来暂时存放 括号
        Stack<Character> stack = new Stack<>();
        for(int i = 0; i < s.length(); i++) {
            char ch = s.charAt(i);
            // 栈为空时，直接将字符放入栈中
            if(stack.isEmpty()) {
                stack.push(ch);
            }else {
                // 若是左括号则直接入栈
                // 若是右括号的话，则与栈中括号进行匹配，匹配成功则出栈，匹配不成功则将 ch 入栈
                if(ch == '(' || ch == '[' || ch == '{') {
                    stack.push(ch);
                }else if(ch == ')' && stack.peek() == '(') {
                    stack.pop();
                }else if(ch == ']' && stack.peek() == '[') {
                    stack.pop();
                }else if(ch == '}' && stack.peek() == '{') {
                    stack.pop();
                }
            }
        }
        // 如果括号符合规定，那么遍历完成后，栈一定为空
        if (stack.isEmpty()) {
            System.out.println(true);
        }else {
            System.out.println(false);
        }
    }
}
